import { ChainInformation, ChainType, Currency } from "types"

/**
 * 以太币
 */
export const ETH: Currency = {
    name: 'Ether',
    symbol: 'ETH',
    decimals: 18,
}

export const MATIC: Currency = {
    name: 'Matic Token',
    symbol: 'MATIC',
    decimals: 18,
}

export const AVAX: Currency = {
    name: 'Avax',
    symbol: 'AVAX',
    decimals: 9,
}

export const ONE: Currency = {
    name: 'ONE Token',
    symbol: 'ONE',
    decimals: 18,
}

export const XDAI: Currency = {
    name: 'xDAI',
    symbol: 'xDAI',
    decimals: 18,
}

/**
 * 币安
 */
export const BNB: Currency = {
    name: 'Binance Token',
    symbol: 'BNB',
    decimals: 18,
}
/**
 * 常用到的链
 */
export const CHAIN_INFORMATION = new Map<number, ChainInformation | ChainType>([
    [
        1,
        {
            id: 1,  // 以太坊主网，使用以太币
            nativeCurrency: ETH,
            type: 'main',
            fullName: 'Ethereum Mainnet',
            shortName: 'Ethereum',
            explorerUrl: `https://etherscan.io`, // 浏览器url
            testnet: false,
        },
    ],
    [
        3,
        {
            id: 3,
            nativeCurrency: ETH,
            type: 'ropsten',   // ropsten 测试网络
            fullName: 'Ropsten Testnet',
            shortName: 'Ropsten',
            explorerUrl: `https://ropsten.etherscan.io`,
            testnet: true,
        },
    ],
    [
        4,
        {
            id: 4,
            nativeCurrency: ETH,
            type: 'rinkeby', // rinkeby 测试网络
            fullName: 'Rinkeby Testnet',
            shortName: 'Rinkeby',
            explorerUrl: `https://rinkeby.etherscan.io`,
            testnet: true,
        },
    ],
    [
        5,
        {
            id: 5,
            nativeCurrency: ETH,
            type: 'goerli',
            fullName: 'Goerli Testnet',
            shortName: 'Goerli',
            explorerUrl: `https://goerli.etherscan.io`,
            testnet: true,
        },
    ],
    [
        42,
        {
            id: 42,
            nativeCurrency: ETH,
            type: 'kovan',
            fullName: 'Kovan Testnet',
            shortName: 'Kovan',
            explorerUrl: `https://kovan.etherscan.io`,
            testnet: true,
        },
    ],
    [
        43112,
        {
            id: 43112,
            nativeCurrency: AVAX,
            type: 'avalocal',
            shortName: 'Avalanche Local',
            fullName: 'Avalanche Local',
            testnet: true,
        },
    ],
    [
        43113,
        {
            id: 43113,
            nativeCurrency: AVAX,
            type: 'fuji',
            fullName: 'Avalanche Fuji',
            shortName: 'Fuji',
            explorerUrl: 'https://cchain.explorer.avax-test.network/',
            testnet: true,
        },
    ],
    [
        43114,
        {
            id: 43114,
            nativeCurrency: AVAX,
            type: 'avalanche',
            fullName: 'Avalanche Mainnet',
            shortName: 'Avalanche',
            explorerUrl: 'https://cchain.explorer.avax.network/',
            testnet: false,
        },
    ],
    [
        100,
        {
            id: 100,
            nativeCurrency: XDAI,
            type: 'xdai',
            fullName: 'xDAI',
            shortName: 'xDAI',
            explorerUrl: 'https://blockscout.com/xdai/mainnet/',
            testnet: false,
        },
    ],
    [
        137,
        {
            id: 137,
            nativeCurrency: MATIC,
            type: 'matic',
            fullName: 'Polygon Mainnet',
            shortName: 'Polygon',
            explorerUrl: `https://polygonscan.com`,
            testnet: false,
        },
    ],
    [
        80001,
        {
            id: 80001,
            nativeCurrency: MATIC,
            type: 'mumbai',
            fullName: 'Mumbai Testnet',
            shortName: 'Mumbai',
            explorerUrl: `https://mumbai.polygonscan.com`,
            testnet: true,
        },
    ],
    [
        1666600000,
        {
            id: 1666600000,
            nativeCurrency: ONE,
            type: 'harmony',
            fullName: 'Harmony ONE',
            shortName: 'Harmony',
            explorerUrl: `https://explorer.harmony.one/`,
            testnet: false,
        },
    ],
    [
        1666700000,
        {
            id: 1666700000,
            nativeCurrency: ONE,
            type: 'harmonyTest',
            fullName: 'Harmony ONE Testnet',
            shortName: 'Harmony Testnet',
            explorerUrl: `https://explorer.testnet.harmony.one/`,
            testnet: true,
        },
    ],
    [
        56,
        {
            id: 56,  // 币安
            nativeCurrency: BNB,
            type: 'bsc',
            fullName: 'Binance Smart Chain',
            shortName: 'BSC',
            explorerUrl: `https://bscscan.com/`,
            testnet: false,
        },
    ],
    [
        97,
        {
            id: 97, // 币安测试网络
            nativeCurrency: BNB,
            type: 'bscTest',
            fullName: 'Binance Smart Chain Testnet',
            shortName: 'BSC Testnet',
            explorerUrl: `https://testnet.bscscan.com/`,
            testnet: true,
        },
    ],
    [
        421611,
        {
            id: 421611,
            nativeCurrency: ETH,
            type: 'arbitrumTest',
            fullName: 'Arbitrum Testnet',
            shortName: 'Arbitrum Testnet',
            explorerUrl: 'https://testnet.arbiscan.io/',
            testnet: true,
        },
    ],
    [
        42161,
        {
            id: 42161,
            nativeCurrency: ETH,
            type: 'arbitrum',
            fullName: 'Arbitrum Mainnet',
            shortName: 'Arbitrum',
            explorerUrl: 'https://arbiscan.io/',
            testnet: false,
        },
    ],
    [
        1337,
        {
            id: 1337,
            type: 'local',
            testnet: true,
        },
    ],
    [
        5777,
        {
            id: 5777,
            type: 'ganache',
            testnet: true,
        },
    ],
])
/**
 * MetaMask 中request请求中的methods 方法
 */
export enum MetaMaskRequestMethods {
    /**
     * 添加一条现在metamask 中不存在的链
     */
    addEthereumChain = "wallet_addEthereumChain",
    /**
     * 添加token 代币到钱包中
     */
    watchAsset = 'wallet_watchAsset',
    /**
     *  获取当前连接网络的链的id
     */
    chainId = 'eth_chainId',
    /**
     * eth_requestAccounts 获取账号(或者可以理解为链接metamask 钱包)
     */
    requestAccounts = 'eth_requestAccounts',
    /**
     * 获取账户地址
     */
    accounts = 'eth_accounts',
    /**
     * 获取最新区块编号
     */
    blockNumber = 'eth_blockNumber'
}
/**
 * 添加一条链到metamask 上时，请求的网络参数
 */
export const AddEthereumChainParams: { [key: number]: any } = {
    8: {
        chainId: "0x8",
        chainName: "Ubiq",
        nativeCurrency: {
            name: "Ubiq Ether",
            symbol: "UBQ",
            decimals: 18,
        },
        rpcUrls: ["https://rpc.octano.dev/"],
        blockExplorerUrls: ["https://ubiqscan.io/"]
    },
    56: {
        chainId: `0x38`,
        chainName: 'Binance Smart Chain Mainnet',
        nativeCurrency: {
            name: 'BNB',
            symbol: 'bnb',
            decimals: 18,
        },
        rpcUrls: ['https://bsc-dataseed1.ninicoin.io', 'https://bsc-dataseed1.defibit.io', 'https://bsc-dataseed.binance.org'],
        blockExplorerUrls: [`https://bscscan.com/`],
    },
}